local GuideConfig = require("excel.Task").Guide
local GuideVarConfig = require("excel.Task").GuideVar
local PanelGuide = require("excel.Task").PanelGuide
local Msg = require("core.Msg")

function sendGuidePanelQueryList(human,index)
	local mm = Msg.gc.GC_GUIDE_PANEL_QUERY_LIST
	mm.index = index
	
	local guideID
	for k,v in pairs(GuideVarConfig) do
		if v.value == index then
			print(PanelGuide[k],index)
			guideID = PanelGuide[k].guideID
			break
		end		
	end
	assert(guideID,index)
	setGuideList(guideID,mm.list)
	Msg.send(mm,human.fd)
end

function sendGuidePanelList(human)
	local mm = Msg.gc.GC_GUIDE_PANEL_LIST
	local len = 0
	for k,v in pairs(PanelGuide) do
		local index = GuideVarConfig[k].value
		if not human.db.guidePanel[index] then
			len = len + 1
			local GuidePanelData = mm.data[len]
			GuidePanelData.index = index
			GuidePanelData.guideID = v.guideID
			GuidePanelData.isEvent = v.isEvent
		end
	end
	
	mm.data[0] = len
	Msg.send(mm,human.fd)
end

function setGuideList(id,list)
	local len=0
	for i=1,21 do
		local config = GuideConfig[id]
		if not config then break end
		len = i
		local guideNode = list[i]
		guideNode.id = id
		guideNode.cmd = config.cmd
		for k,v in ipairs(config.args) do
			guideNode.args[k] = (GuideVarConfig[v] and tostring(GuideVarConfig[v].value)) or tostring(v)
		end
		guideNode.args[0] = #config.args
		guideNode.tip = config.tip
		guideNode.nextGuide = config.nextGuide
		if config.nextGuide==0 then 
			break
		end
		assert(i<=20)
		id = config.nextGuide		
	end	
	list[0] = len
end